package com.yd.app.mapper.provider;

import com.yd.domain.searchParam.PermParam;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author zy
 * @create 2018-03-07 11:19
 * @desc权限
 **/
public class PermissionProvider  extends BaseProvider {
    /**
     * @Author: zy
     * @Desc:查询数据列表
     * @Date:  2018/3/7
     */
    public String searchPermList(Map map){
        PermParam permParam= (PermParam) map.get("permParam");
        StringBuilder sb=new StringBuilder("select p.code,p.title,p.des from sys_perm p " +
                "WHERE 1=1 ");
        sb.append(createSearchSanWhereSql(permParam));
        sb.append("  limit #{startRow},#{pageSize}");
        return sb.toString();
    }
    /**
     * @Author: zy
     * @Desc:查询数据
     * @Date:  2018/3/7
     */
    public String searchPermCount(Map map){
        PermParam permParam= (PermParam) map.get("permParam");
        StringBuilder sb=new StringBuilder("SELECT COUNT(1) from sys_perm p  " +
                "  where 1=1 ");
        sb.append(createSearchSanWhereSql(permParam));
        return sb.toString();
    }
    /**
     * @Author: zy
     * @Desc:权限查询条件
     * @Date:  2018/3/7
     */
    private String createSearchSanWhereSql(PermParam permParam){
        StringBuilder sb=new StringBuilder();
        if(!StringUtils.isEmpty(permParam.getTitle())){
            sb.append(" and p.title like  '%"+permParam.getTitle()+"%'  ");
        }
        if(!StringUtils.isEmpty(permParam.getCode())){
            sb.append(" and p.code = '"+permParam.getCode()+"'  ");
        }
        return sb.toString();
    }
}
